<template>
	<view class="bigBox">
		<u-navbar leftIconColor='#fff' :autoBack="true" bgColor='#000' title='地址管理' titleStyle="color:#fff;">
		</u-navbar>
		<u-radio-group v-model="value" style='display: flex;flex-direction: column;padding-bottom: 200rpx;'>
			<template v-for="item in 10">
				<view class="addressBox" @click="goFanhui(item.ID)">
					<view class="box">
						<view class="icon">
							<image src="@/static/icon/address.png"></image>
						</view>
						<view class="text">
							<view class="top">
								<view class="name">李老板</view>
								<view class="number">1810 **** 2267</view>
							</view>
							<view class="address">广东省广州市越秀区先烈中路80号1906-1907</view>
							<view class="default">
								<u-radio label="默认地址" :name='item' labelSize='28rpx'></u-radio>
							</view>
						</view>
						<view class="icon" @click.stop="goEdit">
							<text>编辑</text>
							<u-icon name='arrow-right' color='#101010'></u-icon>
						</view>
					</view>
				</view>
			</template>
		</u-radio-group>
		<u-popup :show="show" :round="10" @close="close" closeable>
			<view class="addBox">
				<u--form labelPosition="left" :model="model1" :rules="rules" ref="form" labelWidth='70'>
					<u-form-item label="姓名" prop="name" borderBottom >
						<u--input v-model="model1.name" border="none" placeholder="请输入内容"></u--input>
					</u-form-item>
					<u-form-item label="电话" prop="number" borderBottom >
						<u--input v-model="model1.number" maxlength='11' border="none" placeholder="请输入内容"></u--input>
					</u-form-item>
					<u-form-item label="地址选择" borderBottom prop=''>
						<pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
							{{model1.addrss}}
						</pick-regions>
					</u-form-item>
					<u-form-item label="详细地址" prop="Daddress" borderBottom>
						<u--textarea v-model="model1.Daddress" placeholder="请输入内容"></u--textarea>
					</u-form-item>
					<u-form-item borderBottom prop='' label=" ">
						<u-checkbox-group placement="column" @change="checkboxChange">
							<u-checkbox shape='circle' label="是否为默认地址"> </u-checkbox>
						</u-checkbox-group>
					</u-form-item>
				</u--form>
				<view class="dzBtn" v-if="add">添 加 地 址</view>
				<view class="dzBtn" v-else="!add">编 辑 地 址</view>
			</view>
		</u-popup>
		<view class="addBtn" @click="show=true;add=true">
			添 加 地 址
		</view>
	</view>
</template>

<script>
	import pickRegions from '@/components/pick-regions/pick-regions.vue'
	export default {
		components: {
			pickRegions
		},
		data() {
			return {
				value: false,
				show: false,
				add:true,
				model1: {
					name: '',
					addrss: '点击此处选择地址',
					Daddress:'',
					number:'',
					check:false
				},
				region: [],
				defaultRegion: ['湖北省', '恩施土家族苗族自治州', '利川市'],
				defaultRegionCode: '422802',
				rules: {
					name: {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					number: {
						type: 'string',
						required: true,
						len: 11,
						message: '请填写11位手机号',
						trigger: ['blur']
					},
					Daddress:{
						type: 'string',
						required: true,
						message: '请填写详细地址',
						trigger: ['blur', 'change']
					}
				}
			}
		},
		methods: {
			checkboxChange(n) {
				this.model1.check=n
			},
			handleGetRegion(region) {
				this.region = region
				this.model1.addrss = `${region[0].name}-${region[1].name}-${region[2].name}`
			},
			goEdit(ev) {
				console.log(1)
				this.show=true
				this.add=false
				ev.stopPropagation();
			},
			close() {
				this.show = false
				// console.log('close');
			},
			goFanhui() {
				let pages = getCurrentPages()
				// 2. 上一页面实例
				// 注意是length长度，所以要想得到上一页面的实例需要 -2
				// 若要返回上上页面的实例就 -3，以此类推
				let prevPage = pages[pages.length - 2]
				// 3. 给上一页面实例绑定getValue()方法和参数（注意是$vm）
				prevPage.$vm.getValue("item");
				uni.navigateBack({
					delta: 1 // 返回的页面数
				})
			}
		}
	}
</script>

<style>
	.bigBox {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 170rpx;
		height: calc(100vh - 170rpx);
		background-color: #F8F8F8;
	}
</style>
<style lang="less">
	.addBox {
		padding: 60rpx 30rpx;
	}
	.dzBtn{
		margin-top: 40rpx;
		width: 670rpx;
		height: 100rpx;
		line-height: 100rpx;
		border-radius: 8rpx;
		background-color: rgba(22, 132, 252, 100);
		color: rgba(255, 255, 255, 100);
		font-size: 36rpx;
		text-align: center;
	}
	.addBtn{
		position: fixed;
		bottom: 100rpx;
		width: 670rpx;
		height: 100rpx;
		line-height: 100rpx;
		border-radius: 8rpx;
		background-color: rgba(22, 132, 252, 100);
		color: rgba(255, 255, 255, 100);
		font-size: 36rpx;
		text-align: center;
	}

	.addressBox {
		width: 750rpx;
		height: 164rpx;
		background-color: #fff;
		display: flex;
		justify-content: center;
		margin-bottom: 10rpx;

		.box {
			width: 670rpx;
			height: 164rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.icon {
				display: flex;
				color: rgba(190, 199, 209, 100);

				image {
					width: 40rpx;
					height: 40rpx;
				}
			}

			.text {
				height: 140rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-around;

				.top {

					display: flex;
					align-items: center;
					justify-content: flex-start;

					.name {
						font-weight: 700;
						color: rgba(0, 7, 15, 100);
						font-size: 24rpx;
					}

					.number {
						margin-left: 40rpx;
						color: rgba(190, 199, 209, 100);
						font-size: 24rpx;
					}
				}

				.address {
					color: rgba(190, 199, 209, 100);
					font-size: 24rpx;
				}
			}
		}
	}
</style>
